package org.pluslibs.framework.swingplus.utils;

import java.io.*;
import java.awt.Toolkit;
import java.awt.datatransfer.*;

public class ClipboardUtils {
    
    public static void setClipboard(String str) {
    	Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    	StringSelection strSelection = new StringSelection(str);
    	clipboard.setContents(strSelection, strSelection);
    }
    
    public static String getClipboard() {
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        Transferable t = clipboard.getContents(null);
        if ( t!=null && t.isDataFlavorSupported(DataFlavor.stringFlavor )) {
            try {
                return (String) t.getTransferData(DataFlavor.stringFlavor);
            } catch ( IOException e ) {
                e.printStackTrace();
                return null;
            } catch ( UnsupportedFlavorException e ) {
                e.printStackTrace();
                return null;
            }
        } else {
            return null;
        }
    }
    
}
